package com.medvalley.tcm.controller;

import com.medvalley.tcm.base.Result;
import com.medvalley.tcm.domain.MusicDoc;
import com.medvalley.tcm.service.impl.MusicDocService;
import com.medvalley.tcm.vo.outputvo.MusicDocCategoryOutputVo;
import com.medvalley.tcm.vo.outputvo.MusicDocOutputVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/music_doc")
@Api("音乐知识")
public class MusicDocController extends BaseController {

    @Autowired
    private MusicDocService musicDocService;

    @ApiOperation("知识分类列表")
    @GetMapping("/cate_list")
    public Result listCategory(@RequestParam int categoryId) {
        List<MusicDocCategoryOutputVo> outputVos = musicDocService.listCategory(categoryId);
        return success(outputVos);
    }

    @ApiOperation("文章列表")
    @GetMapping("/doc_list")
    public Result listDoc(@RequestParam int categoryId) {
        List<MusicDocOutputVo> outputVos = musicDocService.listMusicDoc(categoryId);
        return success(outputVos);
    }

    @ApiOperation("文章详情")
    @GetMapping("/doc_detail")
    public Result docDetail(@RequestParam int docId) {
        MusicDocOutputVo outputVo = musicDocService.docDetail(docId);
        return success(outputVo);
    }

    @ApiOperation("保存文章")
    @PostMapping("/doc_add")
    public Result saveDoc(@RequestParam int categoryId, @RequestParam String title, @RequestParam String subTitle, @RequestParam String content) {
        MusicDoc musicDoc = new MusicDoc();
        musicDoc.setDocCategory(categoryId);
        musicDoc.setDocContent(content);
        musicDoc.setDocTitle(title);
        musicDoc.setDocSubTitle(subTitle);
        musicDocService.addDoc(musicDoc);
        return success();
    }

}
